package com.catsic.practice.config;

import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.RepositoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @Author: zhangzf
 * @CreateTime: 2025-10-27  09:58
 * @Description: 流程部署配置
 */
/*@Component*/
@Slf4j
public class ProcessDeploymentConfig implements CommandLineRunner{

    @Autowired
    private RepositoryService repositoryService;

    @Override
    public void run(String... args) throws Exception {
        // 检查流程是否已部署
        long count = repositoryService.createProcessDefinitionQuery()
                .processDefinitionKey("12328hot-line-process")
                .count();
        if(count == 0){
            // 从classpath部署BPMN文件
            repositoryService.createDeployment()
                    .addClasspathResource("processes/12328hot-line.bpmn20.xml")
                    .name("12328热线工单审批")
                    .deploy();
            log.info("12328热线工单审批流程部署成功！");
        }
    }
}
